package com.zxy.ziems.server.device.controller;

import com.zxy.ziems.server.device.pojo.dto.ProtocolDTO;
import com.zxy.ziems.server.device.pojo.vo.ProtocolVO;
import com.zxy.ziems.server.device.service.ProtocolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集管理-协议管理控制
 * @author 10348359
 * @create 2024-03-25 14:15
 */
@RestController
@Validated
@RequestMapping("/api")
public class ProtocolController {
    /**
     * 协议新增
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/main/data/protocol/add")
    public void add(@Validated(value = ProtocolDTO.Add.class) @RequestBody ProtocolDTO dto) throws Exception {
        service.add(dto);
    }

    /**
     * 协议更新
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/main/data/protocol/update")
    public void update(@Validated(value = ProtocolDTO.Update.class) @RequestBody ProtocolDTO dto) throws Exception {
        service.update(dto);
    }

    /**
     * 删除协议
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/main/data/protocol/delete")
    public void delete(@Validated(value = ProtocolDTO.Delete.class) @RequestBody ProtocolDTO dto) throws Exception {
        service.deleteById(dto.getId());
    }

    /**
     * 协议列表
     * @return
     */
    @GetMapping("/main/data/protocol/list")
    public List<ProtocolVO> list() throws Exception {
        return service.viewList();
    }


    private ProtocolService service;

    @Autowired
    public void setService(ProtocolService protocolService) {
        this.service = protocolService;
    }

}
